package com.cssw.fyzb.tps.api.vod;

import com.cssw.fyzb.tps.client.VodClient;
import com.cssw.fyzb.tps.model.vo.ProcessMediaVo;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Feng Chen
 */
@Function(description = "处理视频信息",
        parameters = {
                @Parameter(name = "fileId", type = Type.String, description = "视频编号", required = true),
        }, result = @Result(properties = {
        @Property(name = "requestId", type = Type.String, description = "请求编号"),
        @Property(name = "taskId", type = Type.String, description = "任务编号"),
}))
@Component
public class ProcessMedia implements Action {

    @Autowired
    private VodClient vodClient;

    private static final Logger logger = LoggerFactory.getLogger(ProcessMedia.class);

    @Override
    public Response execute(Request request) throws Exception {

        String fileId = request.getString("fileId");

        // 获取任务编号
        try {
            ProcessMediaVo vo = vodClient.processMedia(fileId);
            return Response.success().put("data", vo);
        } catch (Exception e) {
            logger.error("", e);
        }

        return Response.fail("操作异常");
    }

}
